package com.itheima.dao;

import com.itheima.domain.Student;

import java.util.ArrayList;

public class StudentDao {
    private static ArrayList<Student> list= new ArrayList<>();


    //新增
    public void addStudent(Student student){
            list.add(student);
    }
    public ArrayList<Student> findAllStudents(){
        return list;
    }

    public void deleteStudent(String sid){
        int index = getIndex(sid);
        list.remove(index);
    }

    //根据学号找索引
    public int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(student.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
    public void updateStudent(String sid,Student student){
        int index = getIndex(sid);
        list.set(index,student);
    }
}
